<?php
class AttStudentHandler{

private $regno;
private $day;
private $subgr;
private $con;
private $month;


public function setRegno($reg){
	
	$this->regno=$reg;
	}

public function setSubgr($sub){
	
	$this->subgr=$sub;
	}
	
public function setDay($days){
	
	$this->day=$days;
	}

public function setConnect($conn){
	 
	 return $this->con=$conn;
	 }

public function setMonth($months){
	 
	 return $this->month=$months;
	 }
	 
	 
public function attAdd(){


$sql="insert into stud_attend (reg_no,attend_date,sub_gr) values('$this->regno','$this->day','$this->subgr')";
$time_now=mktime(date('H')+5,date('i')+30,date('s'),date('m'),date('d'),date('Y'));

$year=date('Y',$time_now);


$result1=mysql_query("select * from student where reg_no='$this->regno' and year(j_date)='$year'",$this->con) or die(mysql_error());

$count1=mysql_num_rows($result1);

$result2=mysql_query("select * from payment where reg_no='$this->regno' and month(paid_date)='$this->month' and sub_gr='$this->subgr'",$this->con) or die(mysql_error());

$count2=mysql_num_rows($result2);


if(!($count1==0)){

if(!($count2==0)){

mysql_query($sql,$this->con) or die(mysql_error());

echo "Succeessfully Added";

}else{

$msg="Invalid Attendance";
return $msg;
}



}else{

$msg="Invalid User";
return $msg;
}

} 





public function getPageSearch($startrow,$limit){

$sql="select stud_attend.att_id,stud_attend.reg_no,subject_code.subject,subject_code.grade,date(stud_attend.attend_date) as date from stud_attend,subject_code where stud_attend.sub_gr=subject_code.sub_gr order by stud_attend.att_id desc Limit $startrow,$limit ";

$result=mysql_query($sql,$this->con)or die(mysql_error());
return $result;

}




public function getSearch($startrow,$limit){


$sql="select stud_attend.att_id,stud_attend.reg_no,subject_code.subject,subject_code.grade,date(stud_attend.attend_date) as date from stud_attend,subject_code where stud_attend.sub_gr=subject_code.sub_gr and stud_attend.reg_no='$this->regno' and stud_attend.sub_gr ='$this->subgr'and month(stud_attend.attend_date)='$this->month'   order by stud_attend.att_id desc Limit $startrow,$limit ";


$result2=mysql_query($sql,$this->con)or die(mysql_error());
return $result2;

}



public function getDelete($id){
  
  
  $sql="delete from stud_attend where att_id='$id'";
  
  mysql_query($sql,$this->con) or die(mysql_error());;
  
  $msg="deleted";
  
  return $msg; 
  
  
  }
  
 
 
  public function attUpdate($id){
  
  
  
 $sql="update stud_attend set reg_no='$this->regno',attend_date='$this->day',sub_gr='$this->subgr' where att_id='$id' ";
  
  
$time_now=mktime(date('H')+5,date('i')+30,date('s'),date('m'),date('d'),date('Y'));

$year=date('Y',$time_now);


$result1=mysql_query("select * from student where reg_no='$this->regno' and year(j_date)='$year'",$this->con) or die(mysql_error());

$count1=mysql_num_rows($result1);

$result2=mysql_query("select * from payment where reg_no='$this->regno' and month(paid_date)='$this->month' and sub_gr='$this->subgr'",$this->con) or die(mysql_error());

$count2=mysql_num_rows($result2);

  if(!($count1==0)){

if(!($count2==0)){

  mysql_query($sql,$this->con) or die(mysql_error()); 
  
  $msg="Sucessfully Updated";
  
  return $msg;
  }else{

$msg="Invalid Attendance";
return $msg;
}



}else{

$msg="Invalid User";
return $msg;
}
  
  
}
 





 public function getPaginationRow(){


$sql="select stud_attend.att_id,stud_attend.reg_no,subject_code.subject,subject_code.grade,date(stud_attend.attend_date) as date from stud_attend,subject_code where stud_attend.sub_gr=subject_code.sub_gr and stud_attend.reg_no='$this->regno' and stud_attend.sub_gr ='$this->subgr'and month(stud_attend.attend_date)='$this->month' ";


$result2=mysql_query($sql,$this->con)or die(mysql_error());
return $result2;

}


}





?>